package cn.edu.nsmc.modules.sys.controller;

import cn.edu.nsmc.common.utils.PageUtils;
import cn.edu.nsmc.common.utils.R;
import cn.edu.nsmc.modules.sys.entity.SysWorksheetType;
import cn.edu.nsmc.modules.sys.entity.vo.WorksheetTypeVO;
import cn.edu.nsmc.modules.sys.service.SysWorksheetTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;



/**
 * 工单类型
 *
 */
@RestController
@RequestMapping("/sys/worksheet/type")
public class SysWorksheetTypeController {
    @Autowired
    private SysWorksheetTypeService sysWorksheetTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysworksheettype:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysWorksheetTypeService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/tree")
    public R tree(){
         ArrayList<WorksheetTypeVO> list =  sysWorksheetTypeService.tree();
        return R.ok().put("data", list);
    }

    
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        SysWorksheetType sysWorksheetType = sysWorksheetTypeService.getById(id);

        return R.ok().put("sysWorksheetType", sysWorksheetType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysworksheettype:save")
    public R save(@RequestBody SysWorksheetType sysWorksheetType){
		sysWorksheetTypeService.save(sysWorksheetType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysworksheettype:update")
    public R update(@RequestBody SysWorksheetType sysWorksheetType){
		sysWorksheetTypeService.updateById(sysWorksheetType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysworksheettype:delete")
    public R delete(@RequestBody Long[] ids){
		sysWorksheetTypeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
